package com.ruoyi.web.controller.analysis;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.PoPublicOpinion;
import com.ruoyi.system.domain.PublicOpinionEvents;
import com.ruoyi.system.domain.vo.EventParameterVo;
import com.ruoyi.system.domain.vo.NameListValue;
import com.ruoyi.system.domain.vo.NameValue;
import com.ruoyi.system.enums.SensitiveTypeEnum;
import com.ruoyi.system.service.IStatisticAnalysisService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/analysis/statistic")
public class StatisticAnalysisController extends BaseController {

    @Autowired
    private IStatisticAnalysisService statisticAnalysisService;




    /**
     * 获取当前企业内的负面信息
     */
    @ApiOperation("获取当前企业内的负面信息")
    @GetMapping("/getNegativeListOfTenantCode")
    public AjaxResult getNegativeListOfTenantCode(int count) {
        List<PoPublicOpinion> list = statisticAnalysisService.getNegativeListOfTenantCode(count);
        return AjaxResult.success(list);
    }

    /**
     * 获取当前企业内的热门信息
     */
    @ApiOperation("获取当前企业内的热门信息")
    @GetMapping("/getHotListOfTenantCode")
    public AjaxResult getHotListOfTenantCode(int count) {
        List<PoPublicOpinion> list = statisticAnalysisService.getHotListOfTenantCode(count);
        return AjaxResult.success(list);
    }



    /**
     * 今日预警总数
     */
    @ApiOperation("今日预警总数")
    @GetMapping("/getTodayAlertCount")
    public AjaxResult getTodayAlertCount() {
        String tenantCode= SecurityUtils.getLoginUser().getUser().getTenantCode();
        Integer count = statisticAnalysisService.getTodayAlertCount(tenantCode);
        return AjaxResult.success(count);
    }

    /**
     * 今日负面总数
     */
    @ApiOperation("今日负面总数")
    @GetMapping("/getTodayNegativeCount")
    public AjaxResult getTodayNegativeCount() {
        String tenantCode= SecurityUtils.getLoginUser().getUser().getTenantCode();
        Integer count = statisticAnalysisService.getTodayNegativeCount(tenantCode);
        return AjaxResult.success(count);
    }

    /**
     * 今日舆情总数
     */
    @ApiOperation("今日舆情总数")
    @GetMapping("/getTodayPublicOpinionCount")
    public AjaxResult getTodayPublicOpinionCount() {
        String tenantCode= SecurityUtils.getLoginUser().getUser().getTenantCode();
        Integer count = statisticAnalysisService.getTodayPublicOpinionCount(tenantCode);
        return AjaxResult.success(count);
    }

    /**
     * 近七日舆情总数
     */
    @ApiOperation("近七日舆情总数")
    @GetMapping("/getPastSevenDaysPublicOpinionCount")
    public AjaxResult getPastSevenDaysPublicOpinionCount() {
        String tenantCode= SecurityUtils.getLoginUser().getUser().getTenantCode();
        Integer count = statisticAnalysisService.getPastSevenDaysPublicOpinionCount(tenantCode);
        return AjaxResult.success(count);
    }


    /**
     * 负面信息热力图
     */
    @ApiOperation("负面信息热力图")
    @GetMapping("/negativeInformationHeatMap")
    public AjaxResult negativeInformationHeatMap() {
        Map<String, Object> map = new HashMap();
        Date currentDate= DateUtils.getCurrentDate();
        //开始事件选取结束日期前dayNum
        String[] dateList = DateUtils.getDateRange(currentDate,7);
        List<NameListValue> list = statisticAnalysisService.negativeInformationHeatMap();
        map.put("dateList", dateList);
        map.put("heatData", list);
        return AjaxResult.success(map);
    }

    /**
     * 获取正负面信息趋势图
     */
    @ApiOperation(value = "获取正负面信息趋势图", notes = "获取正负面信息趋势图")
    @GetMapping("/getSentimentByPublishTimeByTenantCode")
    public TableDataInfo getSentimentByPublishTimeByTenantCode() {
        List<NameListValue> list = statisticAnalysisService.getSentimentByPublishTimeByTenantCode();
        return getDataTable(list);
    }

    /**
     * 舆情数量按省分组
     */
    @ApiOperation("舆情数量按省分组")
    @GetMapping("/getPublicOpinionCountGroupByProvinceOfTenantCode")
    public AjaxResult getPublicOpinionCountGroupByProvinceOfTenantCode() {
        List<NameValue> list = statisticAnalysisService.getPublicOpinionCountGroupByProvinceOfTenantCode();
        return AjaxResult.success(list);
    }



    @ApiOperation("获取根据时间段获取系统热词")
    @GetMapping("/getHotWords")
    public AjaxResult getHotWords() {
        List<NameValue> hotWords = statisticAnalysisService.getHotWords();
        return AjaxResult.success(hotWords);
    }

    /**
     * 媒体活跃榜
     */
    @ApiOperation("媒体活跃榜")
    @GetMapping("/mostActiveMedia")
    public AjaxResult mostActiveMedia() {
        List<NameValue> list = statisticAnalysisService.getMediaActivity();
        return AjaxResult.success(list);
    }


    /**
     * 意见领袖榜
     */
    @ApiOperation("意见领袖榜")
    @GetMapping("/getOpinionLeaders")
    public AjaxResult getOpinionLeaders() {
        List<NameValue> list = statisticAnalysisService.getOpinionLeaders();
        return AjaxResult.success(list);
    }


}
